package eu.helper;

public class DataTypeConvertor {

	public static int bytesToInt(byte[] bytes) {
		return bytesToInt(bytes,0);
	}

	public static int bytesToInt(byte[] bytes,int pos) {
		int t=0;
		int i=pos+3;
		if(i>=bytes.length)
			i=bytes.length-1;
		for(;i>=pos;i--){
			t=t<<8|bytes[i];
		}
		return t;
	}
	public static byte[] intToBytes(int integer) {
		byte[] targets = new byte[4];
		targets[0] = (byte) (integer & 0xff);// 最低位 
		targets[1] = (byte) ((integer >> 8) & 0xff);// 次低位 
		targets[2] = (byte) ((integer >> 16) & 0xff);// 次高位 
		targets[3] = (byte) (integer >>> 24);// 最高位,无符号右移。 
		return targets; 
	} 
	
	public static void main(String[] args){
		for(byte b:intToBytes(65535)){
			System.out.println(b);
		}
	}

}
